package com.sgb.kjwl.viewmodel.self.logistics;


/*
  1 activity类  2 对应布局  3 适配器  4 每一项布局   5 网络请方法  6 数据模型

 * 说明：承运商机 （物流运输  货主） 网络请求数据
 * */


import com.sgb.kjwl.api.APIManager;
import com.sgb.kjwl.model.entity.self.CarriageBusinessEntity;
import com.swgk.core.base.model.entity.ListResponse;
import com.sgb.kjwl.repository.SelfRepertory;
import com.sgb.kjwl.view.ui.activity.self.logistics.CarriageBusinessActivity;
import com.swgk.core.base.BaseViewModel;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.dialog.DialogHelper;
import com.swgk.core.util.MToast;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;


/*
 *   说明：承运商机  （物流运输  货主）
 *   作者：md
 */


public class CarriageBusinessModel extends BaseViewModel {
    private CarriageBusinessActivity activity;
    public SelfRepertory repertory;


    public CarriageBusinessModel(CarriageBusinessActivity activity, SelfRepertory repertory) {
        this.activity = activity;
        this.repertory = repertory;
    }


    public void getCarriageBusinessModel() {
        DialogHelper.showProgressDialog(activity, null, "数据加载中...", 0, false, null).setCanceledOnTouchOutside(true);
        Map map = new HashMap();
        map.put("page","1");
        map.put("limit","10");

        APIManager.getInstance().getSelfOwnerAPI().myCarriageBusinessList(map).enqueue(new Callback<BaseEntity<ListResponse<List<CarriageBusinessEntity>>>>() {
            @Override
            public void onResponse(Call<BaseEntity<ListResponse<List<CarriageBusinessEntity>>>> call, Response<BaseEntity<ListResponse<List<CarriageBusinessEntity>>>> response) {

                DialogHelper.dismissProgressDialog();
                if (response.body() == null) return;
                if (response.body().getState().equals("ok")) {
                    activity.showCarriageBusiness(response.body().getData().getList());
                } else {
                    assert response.body() != null;
                    MToast.showToast(activity, response.body().getMsg());
                }

            }

            @Override
            public void onFailure(Call<BaseEntity<ListResponse<List<CarriageBusinessEntity>>>> call, Throwable t) {

                DialogHelper.dismissProgressDialog();

            }
        });



    }






}
